import ctypes
import os
import sys

import win32gui
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QApplication

# 设置DPI感知
try:
    ctypes.windll.shcore.SetProcessDpiAwareness(1)
except Exception as e:
    print("注意：无法设置DPI感知，可能导致高分辨率屏幕显示异常。")
# 配置Qt高DPI缩放
os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "1"
os.environ["QT_LOGGING_RULES"] = "qt.qpa.*=false"
QApplication.setHighDpiScaleFactorRoundingPolicy(
    Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
)
Path_chess = "datas/chess/"
Path_chess_big = "datas/chess_big/"
Path_equip = "datas/equip/"
Path_job = "datas/job/"
Path_race = "datas/race/"
Path_job2 = "datas/job2/"
Path_race2 = "datas/race2/"
Path_img = "datas/img/"
Path_img2 = "datas/img2/"
GAME_TITLE = "League of Legends (TM) Client"
GAME_CLASS = "RiotWindowClass"
# 获取窗口的屏幕坐标（包含边框和标题栏）
hwnd = win32gui.FindWindow(GAME_CLASS, GAME_TITLE)
if hwnd != 0:
    rect = win32gui.GetWindowRect(hwnd)
    # 获取客户区尺寸（这里的left/top始终为0，right/bottom是客户区宽高）
    client_rect = win32gui.GetClientRect(hwnd)
    # 将客户区左上角坐标转换为屏幕坐标
    pt_origin = win32gui.ClientToScreen(hwnd, (client_rect[0], client_rect[1]))
    # 将客户区右下角坐标转换为屏幕坐标
    pt_end = win32gui.ClientToScreen(hwnd, (client_rect[2], client_rect[3]))
    # 计算实际物理尺寸
    window_width = pt_end[0] - pt_origin[0]
    window_height = pt_end[1] - pt_origin[1]
    # 直接使用转换后的客户区坐标
    p_left = pt_origin[0]
    p_top = pt_origin[1]
else:
    # 获取显示器物理分辨率
    hdc = ctypes.windll.user32.GetDC(0)
    window_width = ctypes.windll.gdi32.GetDeviceCaps(hdc, 118)  # HORZRES
    window_height = ctypes.windll.gdi32.GetDeviceCaps(hdc, 117)  # VERTRES
    ctypes.windll.user32.ReleaseDC(0, hdc)
    p_left = 0
    p_top = 0
ratio =window_width / 2560  # 比例
if ratio<0.1:
    # 获取显示器物理分辨率
    hdc = ctypes.windll.user32.GetDC(0)
    window_width = ctypes.windll.gdi32.GetDeviceCaps(hdc, 118)  # HORZRES
    window_height = ctypes.windll.gdi32.GetDeviceCaps(hdc, 117)  # VERTRES
    ctypes.windll.user32.ReleaseDC(0, hdc)
    ratio = window_width / 2560  # 比例
    p_left = 0
    p_top = 0
#print(window_width)
# 计算字体大小
base_font_size = 13
# 基准字体大小，适合2560*1440分辨率
new_font_size = int(base_font_size * ratio)
font = QFont("Arial", new_font_size)
prod_gold = {"x": int(857 * ratio), "y": int(1404 * ratio), "color": [210, 184, 126]}

# 小队提醒的位置
prod_area_steps=[int(267*ratio),int(269*ratio),int(269*ratio),int(269*ratio)]

prod_color=[13,19,22] #没有推荐棋子时的颜色  RGB
#挑选的几个位置颜色是否有变化来判断是否出现提醒
prod_x1=int(658*ratio)
prod_x2=int(663*ratio)
prod_x3=int(673*ratio)
prod_x4=int(677*ratio)
prod_x5=int(686*ratio)
prod_y=int(1235*ratio)
#5个商品位置的判断坐标合集
prod_area_list=[]
for prod_area in range(5):
    prod_area_list.append([{"x":prod_x1 +sum(prod_area_steps[:prod_area]) , "y":prod_y},
                           {"x": prod_x2 +sum(prod_area_steps[:prod_area]), "y": prod_y},
                           {"x": prod_x3 +sum(prod_area_steps[:prod_area]), "y": prod_y},
                             {"x": prod_x4 +sum(prod_area_steps[:prod_area]), "y": prod_y},
                           {"x": prod_x5 +sum(prod_area_steps[:prod_area]), "y": prod_y},
                           ])


#扎克组织细胞1072
prod_zack_list=[
{"x":int(877*ratio),"y":int(1398*ratio),"color":[255,246,243]}, #最上面
{"x":int(881*ratio),"y":int(1405*ratio),"color":[255,246,243]},#左边
{"x":int(873*ratio),"y":int(1405*ratio),"color":[255,246,243]},#右边
{"x":int(878*ratio),"y":int(1413*ratio),"color":[255,246,243]},#下边
{"x":int(877*ratio),"y":int(1405*ratio),"color":[79,108,107]}#中间
]


# 边框默认颜色  来判断现在是否是购买棋子界面
prod_box_color = [115, 93, 52]  # 没有推荐棋子时的颜色  RGB
prod_box_pos_list = [
    {"x": int(884 * ratio), "y": int(1222 * ratio)},
    {"x": int(747 * ratio), "y": int(1222 * ratio)},
    {"x": int(1047 * ratio), "y": int(1222 * ratio)},
    {"x": int(1310 * ratio), "y": int(1222 * ratio)},
    {"x": int(1570 * ratio), "y": int(1222 * ratio)},
    {"x": int(1812 * ratio), "y": int(1222 * ratio)},
]
prod_click_x=int(777*ratio)  #第一个商品点击的x
prod_click_y=int(1328*ratio) #第一个商品点击的y
prod_click_pos_list=[]
for i in range(5):
    prod_click_pos_list.append({"x":prod_click_x +sum(prod_area_steps[:i]), "y":prod_click_y})
#这坐标 用来粘贴小队的
xiaodui_bt_pos=[
    {"x":int(2152*ratio),"y":int(32*ratio)},
    {"x": int(1472*ratio), "y": int(254*ratio)},
    {"x": int(1697*ratio), "y": int(815*ratio)},
    {"x": int(2148 * ratio), "y": int(148 * ratio)},
]

ver="1.05"
video_url="https://www.bilibili.com/video/BV1Jc411i7Qj/"
author_url="https://space.bilibili.com/394281846"
author_url="https://space.bilibili.com/394281846"
sponsorship_url="http://w.kami.vip/s/FSUtd45z"

chess_url = "http://game.gtimg.cn/images/lol/act/img/tft/champions/"
chess_big_url = "http://game.gtimg.cn/images/lol/tftstore/s12/624x318/"

# 添加临时路径
temp_path = os.path.dirname(__file__) + "\\"
sys.path.append(temp_path)
# 获取当前的PATH环境变量
original_path = os.environ["PATH"]
os.environ["PATH"] = temp_path + os.pathsep + original_path
